package com.jikedaquan.game.jwt.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充处理器，将全局统一的字段设置默认值
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyMetaObjectHandler.class);

    @Override
    public void insertFill(MetaObject metaObject) {
        //插入数据时对指定字段设置默认值
        LOGGER.info("start insert fill ....");
        this.setFieldValByName("startTime",new Date(),metaObject);
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("status",1,metaObject);


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //更新数据时对指定字段设置默认值
        LOGGER.info("start update fill ....");
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("endTime",new Date(),metaObject);
    }
}
